﻿package mortal.game.view.platform.platformTencent
{
    import Message.DB.Tables.*;
    import Message.Public.*;
    import flash.events.*;
    import mortal.component.window.*;
    import mortal.game.cache.*;
    import mortal.game.events.*;
    import mortal.game.mvc.*;
    import mortal.game.resource.*;
    import mortal.game.utils.*;
    import mortal.game.view.activeTime.*;
    import mortal.game.view.platform.*;
    import mortal.mvc.core.*;
    import mortal.mvc.interfaces.*;

    public class PlatformTencentController extends Controller
    {
        private var _module:PlatformQQModule;

        public function PlatformTencentController()
        {
            return;
        }// end function

        private function checkIsShowIcon() : void
        {
            if (PlatformConst.isQQ())
            {
                if (PlatformTencentUtil.isYellowEnter())
                {
                    PlatformTencentIcon.instance.showIcon(0, 0);
                }
                else if (PlatformTencentUtil.isBlueEnter())
                {
                    PlatformTencentIcon.instance.showIcon(1, 0);
                }
            }
            return;
        }// end function

        private function checkIsReward(param1 = null) : void
        {
            if (!PlatformTencentIcon.isViewShow())
            {
                return;
            }
            var _loc_2:* = PlatformTencentUtil.hasNewHandGiftReward() || PlatformTencentUtil.hasLevelGiftReward() || PlatformTencentUtil.hasDailyLoginGiftReward() || PlatformTencentUtil.hasDailyVipReward() || PlatformTencentUtil.hasDailyDeluxeGiftReward();
            if (_loc_2)
            {
                PlatformTencentIcon.instance.setState(1);
                PlatformTencentIcon.instance.playEffect();
                PlatformTencentIcon.instance.textNumber = this.getRewardNum();
            }
            else
            {
                PlatformTencentIcon.instance.setState(0);
                PlatformTencentIcon.instance.stopEffect();
                PlatformTencentIcon.instance.textNumber = 0;
            }
            return;
        }// end function

        private function getRewardNum() : int
        {
            var _loc_1:int = 0;
            if (PlatformTencentUtil.hasNewHandGiftReward())
            {
                _loc_1++;
            }
            if (PlatformTencentUtil.hasDailyLoginGiftReward())
            {
                _loc_1++;
            }
            if (PlatformTencentUtil.hasDailyDeluxeGiftReward())
            {
                _loc_1++;
            }
            if (PlatformTencentUtil.hasDailyVipReward())
            {
                _loc_1++;
            }
            _loc_1 = _loc_1 + PlatformTencentUtil.getLevelGiftRewardNum();
            return _loc_1;
        }// end function

        private function onPlatformQQBlueGetPastValue(event:DataEvent = null) : void
        {
            PlatformTencentUtil.canGetFlag = true;
            if (PlatformQQBlueXuFeiPanel.isViewShow())
            {
                PlatformQQBlueXuFeiPanel.instance.refresh();
            }
            return;
        }// end function

        private function IsInActivity() : Boolean
        {
            return true;
        }// end function

        override protected function initServer() : void
        {
            NetDispatcher.addCmdListener(ServerCommand.PlatformGiftInfoUpdate, this.onGiftInfoUpdate);
            NetDispatcher.addCmdListener(ServerCommand.PlatformVipInfoUpdate, this.onPlatformInfoUpdate);
            NetDispatcher.addCmdListener(ServerCommand.RoleLevelUpdate, this.updateShow);
            Dispatcher.addEventListener(EventName.PlatformRequestQQYellowGift, this.onRequestGift);
            Dispatcher.addEventListener(EventName.PlatformTencentShow, this.onPlatformViewShow);
            Dispatcher.addEventListener(EventName.PlatformQQBlueXufeiShow, this.onPlatformQQBlueXufeiShow);
            Dispatcher.addEventListener(EventName.PlatformQQBlueGetPastValue, this.onPlatformQQBlueGetPastValue);
            Dispatcher.addEventListener(EventName.ActiveStart, this.activesStartHandler);
            Dispatcher.addEventListener(EventName.ActiveEnd, this.activesEndHandler);
            Dispatcher.addEventListener(EventName.ActiveNotic, this.activesNoticHandler);
            return;
        }// end function

        private function activesStartHandler(event:DataEvent) : void
        {
            var _loc_2:* = event.data as SClientActive;
            if (!PlatformQQBlueXufeiIcon.isViewShow() && _loc_2.type == EActiveType._EActiveTypeTxConRechargeBD)
            {
                if (PlatformTencentUtil.hasXufeiGiftReward())
                {
                    PlatformQQBlueXufeiIcon.instance.show();
                    PlatformQQBlueXufeiIcon.instance.playEffect();
                }
                else if (PlatformTencentUtil.isNormalPast() || PlatformTencentUtil.isDexulePast())
                {
                    PlatformQQBlueXufeiIcon.instance.show();
                    PlatformQQBlueXufeiIcon.instance.playEffect();
                }
            }
            return;
        }// end function

        private function activesEndHandler(event:DataEvent) : void
        {
            var _loc_2:* = event.data as SClientActive;
            if (PlatformQQBlueXufeiIcon.isViewShow() && _loc_2.type == EActiveType._EActiveTypeTxConRechargeBD && (PlatformTencentUtil.isNormalPast() || PlatformTencentUtil.isDexulePast()))
            {
                PlatformQQBlueXufeiIcon.instance.hide();
            }
            return;
        }// end function

        private function activesNoticHandler(event:DataEvent) : void
        {
            return;
        }// end function

        private function onGiftInfoUpdate(param1:Object) : void
        {
            Cache.instance.platform.platformGiftInfo = (param1 as SPublicSeqInt).publicSeqInt;
            this.checkIsShowIcon();
            return;
        }// end function

        private function onPlatformInfoUpdate(param1:Object) : void
        {
            Cache.instance.platform.proxyVipInfo = param1 as SProxyInfo;
            this.checkIsReward();
            this.updateShow();
            Dispatcher.dispatchEvent(new Event(EventName.PlatformQQVipInfoGet));
            var _loc_2:* = ActiveTimeUtil.getSClientActive(EActiveType._EActiveTypeTxConRechargeBD);
            if (_loc_2)
            {
                if (!PlatformQQBlueXufeiIcon.isViewShow() && _loc_2.type == EActiveType._EActiveTypeTxConRechargeBD)
                {
                    if (PlatformTencentUtil.hasXufeiGiftReward())
                    {
                        PlatformQQBlueXufeiIcon.instance.show();
                        PlatformQQBlueXufeiIcon.instance.playEffect();
                    }
                    else if (PlatformTencentUtil.isNormalPast() || PlatformTencentUtil.isDexulePast())
                    {
                        PlatformQQBlueXufeiIcon.instance.show();
                        PlatformQQBlueXufeiIcon.instance.playEffect();
                    }
                }
            }
            return;
        }// end function

        private function onRequestGift(event:DataEvent) : void
        {
            GameProxy.Platform.getPlatformGift(int(event.data), this.onGetPlatformVIPGiftSuccess);
            return;
        }// end function

        private function onGetPlatformVIPGiftSuccess(param1) : void
        {
            var _loc_2:* = param1.userObject;
            Cache.instance.platform.platformGiftInfo.push(int(_loc_2));
            this.updateShow();
            if (PlatformTencentUtil.isBlueEnter())
            {
                this.QQVipGiftStatistics(_loc_2);
            }
            return;
        }// end function

        private function onShow(event:WindowEvent) : void
        {
            return;
        }// end function

        private function onClose(event:WindowEvent) : void
        {
            return;
        }// end function

        override protected function initView() : IView
        {
            if (this._module == null)
            {
                this._module = new PlatformQQModule();
                this._module.addEventListener(WindowEvent.SHOW, this.onShow);
                this._module.addEventListener(WindowEvent.CLOSE, this.onClose);
            }
            return this._module;
        }// end function

        private function onPlatformViewShow(event:Event) : void
        {
            GameUtil.QQVipStatistics(ModuleTypeConst.QQBlueIconClick);
            if (!isViewShow)
            {
                view.show();
            }
            else
            {
                view.hide();
            }
            return;
        }// end function

        private function onPlatformQQBlueXufeiShow(param1 = null) : void
        {
            if (PlatformQQBlueXufeiIcon.isViewShow())
            {
                PlatformQQBlueXufeiIcon.instance.stopEffect();
            }
            if (!PlatformQQBlueXuFeiPanel.isViewShow())
            {
                PlatformQQBlueXuFeiPanel.instance.show();
            }
            return;
        }// end function

        private function updateShow(param1 = null) : void
        {
            if (isViewShow)
            {
                this._module.refresh();
            }
            if (PlatformQQBlueXuFeiPanel.isViewShow())
            {
                PlatformQQBlueXuFeiPanel.instance.refresh();
            }
            this.checkIsReward();
            return;
        }// end function

        private function QQVipGiftStatistics(param1:int) : void
        {
            var _loc_2:TPlatformGift = null;
            if (PlatformGiftConfig.instance.newHandGift && PlatformGiftConfig.instance.newHandGift.id == param1)
            {
                GameUtil.QQVipStatistics(ModuleTypeConst.QQBlueNewHandGift);
            }
            else if (PlatformGiftConfig.instance.dailyLoginGift && PlatformGiftConfig.instance.dailyLoginGift.id == param1)
            {
                GameUtil.QQVipStatistics(ModuleTypeConst.QQBlueDailyVipYearGift);
            }
            else if (PlatformGiftConfig.instance.dailyDeluxeGift && PlatformGiftConfig.instance.dailyDeluxeGift.id == param1)
            {
                GameUtil.QQVipStatistics(ModuleTypeConst.QQBlueDailyVipDeluxeGift);
            }
            else
            {
                _loc_2 = PlatformGiftConfig.instance.getPlatformGiftById(param1);
                if (_loc_2.extend == PlatformGiftConst.VipGift)
                {
                    GameUtil.QQVipStatistics(ModuleTypeConst.QQBlueDailyVipGift);
                }
                else if (_loc_2.extend == PlatformGiftConst.LevelGift)
                {
                    switch(_loc_2.lvLimit)
                    {
                        case 10:
                        {
                            GameUtil.QQVipStatistics(ModuleTypeConst.QQBlueLevel10Gift);
                            break;
                        }
                        case 20:
                        {
                            GameUtil.QQVipStatistics(ModuleTypeConst.QQBlueLevel20Gift);
                            break;
                        }
                        case 30:
                        {
                            GameUtil.QQVipStatistics(ModuleTypeConst.QQBlueLevel30Gift);
                            break;
                        }
                        case 40:
                        {
                            GameUtil.QQVipStatistics(ModuleTypeConst.QQBlueLevel40Gift);
                            break;
                        }
                        case 50:
                        {
                            GameUtil.QQVipStatistics(ModuleTypeConst.QQBlueLevel50Gift);
                            break;
                        }
                        case 60:
                        {
                            GameUtil.QQVipStatistics(ModuleTypeConst.QQBlueLevel60Gift);
                            break;
                        }
                        case 70:
                        {
                            GameUtil.QQVipStatistics(ModuleTypeConst.QQBlueLevel70Gift);
                            break;
                        }
                        default:
                        {
                            break;
                        }
                    }
                }
            }
            return;
        }// end function

    }
}
